package cn.gson.seventh.service;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Sort;
import org.springframework.data.domain.Sort.Direction;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import cn.gson.seventh.model.dao.SeventhDao;
import cn.gson.seventh.model.entity.User;

@Service
@Transactional
public class SevenService {
	@Autowired
	private SeventhDao sd;

	public Iterable<User> getList() {
		return sd.findAll(new Sort(Direction.DESC, "uid"));
	}

	public boolean addUser(User u) {
		sd.save(u);
		return u.getUid() != null;
	}

	public User selectById(Long uid) {
		return sd.findOne(uid);
	}

	public boolean updateUser(User u) {
		User user = sd.findOne(u.getUid());
		user.setUserName(u.getUserName());
		user.setGender(u.getGender());
		return true;
	}

	public void deleteUser(Long uid) {
		sd.delete(uid);
	}
}
